package com.jumper.mydemo.statics;

import java.io.IOException;
import java.util.Map;

import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.stereotype.Component;

public class MetadataAsmDemo {
    public static void run() throws IOException {
        SimpleMetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory();
		MetadataReader metadataReader = readerFactory.getMetadataReader("com.jumper.mydemo.my.MyBean");
		AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
		System.out.println("AnnotationMetadata impl class is " + annotationMetadata.getClass());

		boolean isComponent = annotationMetadata.hasAnnotation(Component.class.getName());
		System.out.println("MyBean is a @Component:" + isComponent);
		
		if (isComponent) {
			Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(Component.class.getName());
			System.out.println("@Component value is " + annotationAttributes.get("value"));
		}
    }
}
